﻿using System.IO.IsolatedStorage;

namespace PocketBlueBird.Configuration
{
    public class MyApplicationSetting
    {
        static IsolatedStorageSettings _appSetting = IsolatedStorageSettings.ApplicationSettings;

        static MyApplicationSetting _myAppSetting;

        public static MyApplicationSetting MyAppSetting
        {
            get
            {
                if (_myAppSetting == null)
                {
                    _myAppSetting = new MyApplicationSetting();
                }

                return _myAppSetting;
            }
        }

        private MyApplicationSetting() { }

        public object this[string key]
        {
            get
            {
                if (_appSetting.Contains(key))
                {
                    return _appSetting[key];
                }
                else
                {
                    return null;
                }
            }
            set
            {
                if (_appSetting.Contains(key))
                {
                    if (value == null)
                    {
                        _appSetting.Remove(key);
                    }
                    else
                    {
                        _appSetting[key] = value;
                    }
                }
                else
                {
                    _appSetting.Add(key, value);
                }
            }
        }
    }
}
